home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 20.5 KB | 582 lines | [TEXT/MPS ] |
- // UDocument.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UDOCUMENT__
- #define __UDOCUMENT__
-
- // MacApp
-
- #ifndef __UCOMMANDHANDLER__
- #include "UCommandHandler.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- #ifndef __USCRIPTABLEOBJECT__
- #include "UScriptableObject.h"
- #endif
-
- // CALib
-
- #if qContainer
- #ifndef _CADEFS_
- #include "CADefs.h"
- #endif
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TCloseDocCommand;
- class TDesignator;
- class TDocument;
- class TFile;
- class TList;
- class TPrintHandler;
- class TPrintInfo;
- class TSaveDocCommand;
- class TStream;
- class TView;
- class TWindow;
-
- //----------------------------------------------------------------------------------------
- // CWindowIterator
- //----------------------------------------------------------------------------------------
-
- class CWindowIterator : public CObjectIterator
- {
- public:
- CWindowIterator(const TDocument* itsDocument,
- ArrayIndex itsLowBound, ArrayIndex itsHighBound,
- Boolean itsForward);
-
- CWindowIterator(const TDocument* itsDocument, Boolean itsForward);
-
- CWindowIterator(const TDocument* itsDocument);
-
- virtual ~CWindowIterator();
-
- inline TWindow* CurrentWindow()
- { return (TWindow *)this->CurrentObject(); }
- // returns the current window
-
- inline TWindow* FirstWindow()
- { return (TWindow*)this->FirstObject(); }
- // return the first window in the iteration
-
- inline TWindow* NextWindow()
- { return (TWindow*)this->NextObject(); }
- // advances the iteration and then returns the window
- };
-
-
- //----------------------------------------------------------------------------------------
- // TDocument: Corresponds to a Finder document. Manages document data in files and in main
- // memory.
- //----------------------------------------------------------------------------------------
-
- class TDocument : public TCommandHandler, public MScriptableObject
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TDocument();
- // Constructor
-
- void IDocument();
- // Initialization method for TDocument.
-
- virtual ~TDocument();
- // This does not call FreeData by default, since you may need to control the order
- // in which things are freed. Your override of TDocument::Free can call FreeData if
- // convenient.
-
- virtual void FreeData();
- // Called when a document is reverted, in order to free it's data objects. You may
- // also wish to call this from you document's Free method, if convenient.
-
- virtual void FreeFromClipboard();
- // Called to free a Clipboard document. Simply calls Free.
-
- virtual Boolean GetIsGhostDocument() const;
-
- virtual void SetIsGhostDocument(const Boolean newIsGhostDocument);
-
- virtual void RegainControl();
- // Called just after the application has been resumed to allow the
- // document to make any necessary adjustments to outside activities.
-
- //------------------------------------------------------------------------------------
- // Opening / Printing Documents
- //------------------------------------------------------------------------------------
-
- virtual Boolean FindDocument(TFile* aFile);
- // True if this document is already open
-
- virtual void DoInitialState();
- // Called for 'New', 'Revert' to blank, Open Tool. Default is to do nothing; You
- // may need to do further initialization that you would not do in case of an Open
-
- virtual void DoMakeViews(Boolean forPrinting);
- // Create all necessary views for this document (based on forPrinting flag) and
- // store into fields of your document. The document will then be sent Print.
-
- virtual void DoPostMakeViews(Boolean forPrinting);
- // Called after DoMakeViews. Calls ShowWindows.
-
- virtual void AttachPrintHandler(TPrintHandler* itsPrintHandler);
- // Creates a TPrintMenuBehavior and adds it to this document
-
- virtual void DetachPrintHandler(TPrintHandler* itsPrintHandler);
- // Deletes a TPrintMenuBehavior that's been added to this document
-
- virtual void OpenAgain(CommandNumber itsCommandNumber, TDocument* openingDoc);
- // Called if the user tries to open the same document twice. openingDoc will be
- // the document object being opened (note that this is not true for TApplication::OpenOld,
- // for which openingDoc is null). Default brings this to the front and calls
- // Failure(noErr, 0), which will abort opening the document. (The goal is to
- // prevent the user from having 2 copies of the same document open, in which case
- // they could make incompatible changes to both.) You might override this if you
- // want to open a second window on the same document. In the ideal case, you
- // should make both windows display exactly the same data, and changes made to one
- // should be reflected in the other. You could also override this to create a
- // read-only copy of the document.
-
- virtual short PoseSaveDialog();
- // If the document has been changed (fChangeCount > 0), then the user is asked to
- // save the document. PoseSaveDialog returns cancel, kYesButton or kNoButton,
- // depending on the button chosen by the user. If the document has not been
- // changed then kNoButton is returned.
-
- virtual void ReadDocument(Boolean forPrinting);
- // Called to read an existing file for display or printing.
-
- virtual void ReadStationery(TFile* itsNewFile);
- // Called to read an existing stationery pad and display its contents in a new
- // untitled document.
-
- virtual void ShowWindows();
- // Called when opening the document initially; default is to call OpenWindow for
- // all windows that have fFlags.openInitially true
-
- virtual void UntitledName(CStr255& noName);
- // Called to supply a name for an untitled document. If this returns '' then the
- // windows are not renamed from the value specified in their titles.
-
-
- //------------------------------------------------------------------------------------
- // Saving Documents
- //------------------------------------------------------------------------------------
-
- virtual long GetChangeCount();
- // Gets the document change count
-
- // Added for 3.5
- virtual Boolean IsChanged();
- // If the document has been changed
-
- virtual void SetChangeCount(long newChangeCount);
- // Sets the document change count
-
- virtual void GetSaveLocation(CommandNumber itsCommandNumber, CAEDesc& theSaveDesc);
- // Creates an CAEDesc describing where the document would be saved
-
- virtual void DoSave(CommandNumber itsCommandNumber);
- // Handle the cSave, cSaveAs, and cSaveCopy commands
-
- virtual void SaveDocument(CommandNumber itsCommandNumber);
- // Try to save the document to disk
-
- virtual void SaveAgain(CommandNumber itsCommandNumber, TDocument* savingDoc);
- // Called when the user tries to Save As or Save a Copy In and specifies the name
- // of a document that is already opened. The default case calls
- // Failure(errSaveAgain, messageSaveFailed) to display an error. (The goal is to
- // prevent the user from having 2 copies of the same document open, in which case
- // they might make incompatible changes to both copies.) savingDoc is the document
- // being saved
-
-
- //------------------------------------------------------------------------------------
- // Closing Documents
- //------------------------------------------------------------------------------------
-
- virtual void Close();
- // Close a document. Notifies others of closing and then closes up all
- // associated windows. ??? NOTE: Must never be called for a document
- // related to a view in the Clipboard.
-
- virtual void CloseAndFree();
- // Close a document and free it.
-
- virtual TCloseDocCommand* MakeCloseCommand();
- // This method creates a document saving command appropriate to this type
- // of document.
-
- virtual void DoClose(CommandNumber aCommand,
- Boolean useAppleEvent = TRUE);
- // This method creates a document closing command appropriate to this type
- // of document and then posts it. Pass a FALSE if this close is NOT
- // supposed to generate an AppleEvent.
-
- //------------------------------------------------------------------------------------
- // Revert
- //------------------------------------------------------------------------------------
-
- virtual void RevertDocument();
- // IF fSaveExists is true then reverts to the file saved on disk, otherwise merely
- // resets the print handler and calls doInitialState. Calls FreeData to free any
- // existing data and commits any currently active command.
-
- virtual void Abandon();
- // Called when a document is closed and changes are being abandoned. For memory
- // based documents the default behaviour of doing nothing is OK. For disk based
- // documents that change the original copy this is the place to override to put
- // back the original contents if you still have it available somewhere (a scratch
- // file?)
-
- virtual void ShowReverted();
- // Called after Revert to show brand new document; default tells each view to
- // ShowReverted
-
-
- //------------------------------------------------------------------------------------
- // Miscellaneous
- //------------------------------------------------------------------------------------
-
- virtual void DoWriteData(const OSType aScrapType,
- TDesignator* aDesignator,
- TStream* aStream);
- // Given a designator and a stream, writes the designated data to the stream.
-
- virtual void DoReadData(const OSType aScrapType,
- TDesignator* aDesignator,
- TStream* aStream, long length);
- // Given a designator and a stream, read the designated data from the stream.
-
-
- //------------------------------------------------------------------------------------
- // designator management methods
- //------------------------------------------------------------------------------------
-
- virtual TDesignator* GetUserSelection();
- // Returns the designator for the user selection (if any).
-
- virtual void SetUserSelection(TDesignator* newSelection);
- // Sets the designator for the user selection (if any).
-
- virtual void UserSelectionChanged(TView* changedView);
- // Call this whenever the user's selection changes. Subclasses should implement
- // the appropriate behavior for their corresponding user selection TDesignator.
-
- virtual void RevealSelection(TDesignator* aSelection);
- // OVERRIDE this; bring this designation into user's view
-
- virtual void RevealUndoRedo(TCommand* command); // override
- // Make this context visible after undo/redo.
-
- virtual void GetTitle(CStr255& aTitle);
- // Returns the name of the fFile or '' if the file does not exist
-
- virtual void SetTitle(const CStr255& aTitle);
- // Does fFile->SetName to aTitle and calls SetTitleForDoc for each window of the
- // document.
-
- virtual void Changed(ChangeID theChange,
- TObject* changedBy);
- // Updates fChangeCount. Calls Inherited::Changed to notify dependents.
-
-
- //------------------------------------------------------------------------------------
- // Command Handlers
- //------------------------------------------------------------------------------------
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);
- // Handles the default menu commands associated with a document and must be
- // overridden to handle any additional items.
-
- virtual void DoSetupMenus();
- // Setup the documents menus, this handles the default menus and must be
- // overridden for any additional items.
-
-
- //------------------------------------------------------------------------------------
- // Hierarchy
- //------------------------------------------------------------------------------------
-
- virtual void AddView(TView* aView);
- // Adds the view to the end of the document's view list.
-
- virtual void AddWindow(TWindow* aWindow);
- // Adds the window to the end of the document's window list.
-
- virtual void CloseWindow(TWindow* aWindow);
- // Called to close a window associated with a document. Document gets to
- // decide whether to really close the window or not and whether to close itself or
- // if there are no more windows. Does nothing if the window is not associated with the doc.
-
- virtual void DeleteView(TView* viewToDelete);
- // Deletes the view from the document's view list.
-
- virtual void DeleteWindow(TWindow* windowToDelete);
- // Deletes the window from the document's window list.
-
- //------------------------------------------------------------------------------------
- // Scripting Support
- //------------------------------------------------------------------------------------
-
- virtual DescType GetSpecifierForm(); // override
-
- virtual void DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Dispatches the send document event
-
- virtual MScriptableObject* GetContainedObject(DescType desiredType,
- DescType selectionForm,
- const CAEDesc& selectionData);
-
- virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType);
-
- virtual void GetSetPropertyInfo(DescType whichProperty,
- CommandNumber& cmdNum,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler* &theContext);
-
- virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty);
-
- virtual void DoAESetData(TAppleEvent* message,
- TAppleEvent* reply);
-
- virtual void DoAEClose(TAppleEvent* message,
- TAppleEvent* reply);
-
- virtual void DoAERevert(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAESave(TAppleEvent* message,
- TAppleEvent* reply);
-
- //------------------------------------------------------------------------------------
- // Container Application Support
- //------------------------------------------------------------------------------------
-
- #if qContainer
- virtual CADocumentRef GetContainer();
- // Override to return the container document reference.
- // For CALib we have to break the encapsulation of TWindow and TDocument
- // so we can find its CADocumentRef.
- // $$$$$ This method will go away as soon as we can find a better way to
- // convert a WindowPtr to a CADocumentRef.
- #endif
-
- protected:
- short OpenWindowCount();
-
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
-
- public:
- CStr255 fTitle; // Title of the document
-
- TList* fWindowList; // list of windows belonging to this
- // document
-
- TList* fViewList; // list of views belonging to document
-
- TDesignator* fUserSelection; // When there is a single user-selection
- // for a document this is it.
-
- TPrintInfo* fPrintInfo; // if non-NULL, this is an object that has
- // the print setup and job info records
-
- long fChangeCount; // master count of changes since last Save
-
- Boolean fSavePrintInfo; // if true for a document saved on disk,
- // the 'print info' record of the
- // fDocPrintHandler will be written out to
- // the data fork before other writing
- // takes place
-
- Boolean fSaveUserSelection; // if true, the user selection will be saved
-
- #if qAttachable
- Boolean fSaveAttachedScript; // if true, the attached script will be saved
- #endif
-
- Boolean fSharePrintInfo; // if true, then all printHandlers
- // associated with views belonging to the
- // same document will share the same
- // 'print info' record
-
- Boolean fReopenAlert; // whether to give an alert if user
- // reopens doc
-
- Boolean fAskOnClose; // Ask to save before closing
-
- Boolean fCommitOnSave; // Commit the last command before saving
- // the document, if it affected the
- // document. This defaults to true, but
- // carefully written applications could
- // set this false.
- protected:
-
- Boolean fIsGhostDocument; // If true, the document iterator of type
- // CNoGhostDocs will skip this document.
- // Will be true if this document is a clipboard
- // document, or if it is a non-scriptable document
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
-
- static short gNumUntitled;
- // The number to assign to the next Untitled document (assuming that the app provides
- // a template for filling in the number. You must change STR# resource with ID 0/ index
- // 3 to read (for example) Untitled-<<<#>>>.
-
- };
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand: Tells the document to save itself.
- //----------------------------------------------------------------------------------------
-
- class TSaveDocCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TSaveDocCommand();
- virtual ~TSaveDocCommand();
-
- void ISaveDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument);
- void ISaveDocCommand(TDocument* itsDocument,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Initialize the TSaveDocCommand procedurally.
-
- virtual void DoIt();
- // Actually perform the document saving.
-
- virtual TAppleEvent* MakeAppleEvent();
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TDocument* fDocument; // The document to close
-
- protected:
- TAppleEvent* fMessage;
- TAppleEvent* fReply;
-
- enum
- {
- kDoSave,
- kDontSave,
- kAskSave
- };
-
- short fSavingState;
- };
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand: Tells the document to revert after checking with the user.
- //----------------------------------------------------------------------------------------
-
- class TRevertDocCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TRevertDocCommand();
- // Constructor
- virtual ~TRevertDocCommand();
- // Destructor
-
- Boolean IRevertDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument);
- void IRevertDocCommand(TDocument* itsDocument,
- TAppleEvent* message,
- TAppleEvent* reply,
- Boolean* statusP);
- // Initialize the RevertDocCommand procedurally.
-
- virtual void DoIt();
- // tell the document to revert if the user says OK.
-
- virtual TAppleEvent* MakeAppleEvent();
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TDocument* fChangedDocument; // the document changed by this command
-
- protected:
- Boolean* fInProcessP;
- };
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand: Closes a document.
- //----------------------------------------------------------------------------------------
-
- class TCloseDocCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TCloseDocCommand();
- virtual ~TCloseDocCommand();
-
- void ICloseDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument);
- void ICloseDocCommand(TDocument* itsDocument,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Initialize the CloseDocCommand procedurally.
-
- virtual TAppleEvent* MakeAppleEvent();
- // Make an Apple Event equivalent to the command.
-
- virtual void DoIt();
- // Actually perform the document closing.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TDocument* fDocument; // The document to close
-
- protected:
- TAppleEvent* fMessage;
- TAppleEvent* fReply;
-
- enum ESavingState
- {
- kUnknown,
- kAskSave,
- kDoSave,
- kDontSave,
- kCancelled
- };
-
- ESavingState fSavingState;
-
-
- };
-
- #endif // __UDOCUMENT__
-